home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWBitVec - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/bitvec.h> RWBitVec v; DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn Class RRRRWWWWBBBBiiiittttVVVVeeeecccc is a bitvector whose length can be changed at run time. Because this requires an extra level of indirection, this makes it slightly less efficient than classes RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((ssssiiiizzzzeeee)))) or RRRRWWWWTTTTBBBBiiiittttVVVVeeeecccc<<<<ssssiiiizzzzeeee>>>>, whose lengths are fixed at compile time. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Simple EEEExxxxaaaammmmpppplllleeee #include <rw/bitvec.h> #include <rw/rstream.h> main(){ // Allocate a vector with 20 bits, set to TRUE: RWBitVec av(20, TRUE); av(2) = FALSE; // Turn bit 2 off av.clearBit(7); // Turn bit 7 off av.setBit(2); // Turn bit 2 back on for(int i=11; i<=14; i++) av(i) = FALSE; cout << av << endl; // Print the vector out } PPPPrrrrooooggggrrrraaaammmm oooouuuuttttppppuuuutttt:::: [ 1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 1 1 1 1 1 PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss ] RWBitVec(); PPPPaaaaggggeeee 1111 RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) Construct a zero lengthed (null) vector. RWBitVec(size_t N); Construct a vector with NNNN bits. The initial value of the bits is undefined. RWBitVec(size_t N, RWBoolean initVal); Construct a vector with NNNN bits, each set to the Boolean value iiiinnnniiiittttVVVVaaaallll. RWBitVec(const RWByte* bp, size_t N); Construct a vector with NNNN bits, initialized to the data in the array of bytes pointed to by bbbbpppp. This array must be at least long enough to contain NNNN bits. The identifier RRRRWWWWBBBByyyytttteeee is a typedef for an uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr. RWBitVec(const RWBitVec& v); Copy constructor. Uses value semantics -- the constructed vector will be a copy of vvvv. ~RWBitVec(); The destructor. Releases any allocated memory. AAAAssssssssiiiiggggnnnnmmmmeeeennnntttt OOOOppppeeeerrrraaaattttoooorrrrssss RWBitVec& ooooppppeeeerrrraaaattttoooorrrr====(const RWBitVec& v); Assignment operator. Value semantics are used -- self will be a copy of vvvv. RWBitVec& ooooppppeeeerrrraaaattttoooorrrr====(RWBoolean b); Assignment operator. Sets every bit in self to the boolean value bbbb. RWBitVec& ooooppppeeeerrrraaaattttoooorrrr&&&&====(const RWBitVec& v); RWBitVec& ooooppppeeeerrrraaaattttoooorrrr^^^^====(const RWBitVec& v); RWBitVec& ooooppppeeeerrrraaaattttoooorrrr||||====(const RWBitVec& v); PPPPaaaaggggeeee 2222 RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) Logical assignments. Set each element of self to the logical AND, XOR, or OR, respectively, of self and the corresponding bit in vvvv. Self and vvvv must have the same number of elements (iiii....eeee...., be conformal) or an exception of type RRRRWWWWIIIInnnntttteeeerrrrnnnnaaaallllEEEErrrrrrrr will occur. IIIInnnnddddeeeexxxxiiiinnnngggg OOOOppppeeeerrrraaaattttoooorrrrssss RWBitRef ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i); Returns a reference to bit iiii of self. A helper class, RRRRWWWWBBBBiiiittttRRRReeeeffff, is used. The result can be used as an lvalue. The index iiii must be between 0 and the length of the vector less one. Bounds checking is performed. If the index is out of range, then an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrr will occur. RWBitRef ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i); Returns a reference to bit iiii of self. A helper class, RRRRWWWWBBBBiiiittttRRRReeeeffff, is used. The result can be used as an lvalue. The index iiii must be between 0 and the length of the vector less one. Bounds checking is performed only if the preprocessor macro RRRRWWWWBBBBOOOOUUUUNNNNDDDDSSSS____CCCCHHHHEEEECCCCKKKK has been defined before including the header file <<<<rrrrwwww////bbbbiiiittttvvvveeeecccc....hhhh>>>>. If so, and if the index is out of range, then an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrr will occur. RWBoolean ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i) const; Returns the boolean value of bit iiii. The result cannot be used as an lvalue. The index iiii must be between 0 and the length of the vector less one. Bounds checking is performed. If the index is out of range, then an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrr will occur. RWBoolean ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i) const; Returns the boolean value of bit iiii. The result cannot be used as an lvalue. The index iiii must be between 0 and the length of the vector less one. Bounds checking is performed only if the preprocessor macro RRRRWWWWBBBBOOOOUUUUNNNNDDDDSSSS____CCCCHHHHEEEECCCCKKKK has been defined before including the header file <<<<rrrrwwww////bbbbiiiittttvvvveeeecccc....hhhh>>>>. If so, and if the index is out of range, then an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrr will occur. LLLLooooggggiiiiccccaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWBoolean ooooppppeeeerrrraaaattttoooorrrr========(const RWBitVec& u) const; Returns TTTTRRRRUUUUEEEE if self and vvvv have the same length and if each bit of self PPPPaaaaggggeeee 3333 RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) is set to the same value as the corresponding bit in vvvv. Otherwise, returns FFFFAAAALLLLSSSSEEEE. RWBoolean ooooppppeeeerrrraaaattttoooorrrr!!!!====(const RWBitVec& u) const; Returns FFFFAAAALLLLSSSSEEEE if self and vvvv have the same length and if each bit of self is set to the same value as the corresponding bit in vvvv. Otherwise, returns TTTTRRRRUUUUEEEE. RWBoolean ooooppppeeeerrrraaaattttoooorrrr========(RWBoolean b) const; Returns TTTTRRRRUUUUEEEE if every bit of self is set to the boolean value bbbb. Otherwise FFFFAAAALLLLSSSSEEEE. RWBoolean ooooppppeeeerrrraaaattttoooorrrr!!!!====(RWBoolean b) const; Returns FFFFAAAALLLLSSSSEEEE if every bit of self is set to the boolean value bbbb. Otherwise TTTTRRRRUUUUEEEE. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void cccclllleeeeaaaarrrrBBBBiiiitttt(size_t i); Clears (iiii....eeee...., sets to FFFFAAAALLLLSSSSEEEE) the bit with index iiii. The index iiii must be between 0 and the length of the vector less one. No bounds checking is performed. The following are equivalent, although cccclllleeeeaaaarrrrBBBBiiiitttt((((ssssiiiizzzzeeee____tttt)))) is slightly smaller and faster than using ooooppppeeeerrrraaaattttoooorrrr(((())))((((ssssiiiizzzzeeee____tttt)))): a(i) = FALSE; a.clearBit(i); const RWByte* ddddaaaattttaaaa() const; Returns a ccccoooonnnnsssstttt pointer to the raw data of self. Should be used with care. PPPPaaaaggggeeee 4444 RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) size_t ffffiiiirrrrssssttttFFFFaaaallllsssseeee() const; Returns the index of the first FFFFAAAALLLLSSSSEEEE bit in self. Returns RRRRWWWW____NNNNPPPPOOOOSSSS if there is no FFFFAAAALLLLSSSSEEEE bit. size_t ffffiiiirrrrssssttttTTTTrrrruuuueeee() const; Returns the index of the first TTTTRRRRUUUUEEEE bit in self. Returns RRRRWWWW____NNNNPPPPOOOOSSSS if there is no TTTTRRRRUUUUEEEE bit. unsigned hhhhaaaasssshhhh() const; Returns a value suitable for hashing. RWBoolean iiiissssEEEEqqqquuuuaaaallll(const RWBitVec& v) const; Returns TTTTRRRRUUUUEEEE if self and vvvv have the same length and if each bit of self is set to the same value as the corresponding bit in vvvv. Otherwise, returns FFFFAAAALLLLSSSSEEEE. size_t lllleeeennnnggggtttthhhh() const; Returns the number of bits in the vector. ostream& pppprrrriiiinnnnttttOOOOnnnn(ostream& s) const; Print the vector vvvv on the output stream ssss. See the example above for a sample of the format. void rrrreeeessssiiiizzzzeeee(size_t N); Resizes the vector to have length NNNN. If this results in a lengthening of the vector, the additional bits will be set to FFFFAAAALLLLSSSSEEEE. istream& ssssccccaaaannnnFFFFrrrroooommmm(istream&); PPPPaaaaggggeeee 5555 RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) Read the bit vector from the input stream ssss. The vector will dynamically be resized as necessary. The vector should be in the same format printed by member function pppprrrriiiinnnnttttOOOOnnnn((((oooossssttttrrrreeeeaaaammmm&&&&)))). void sssseeeettttBBBBiiiitttt(size_t i); Sets (iiii....eeee...., sets to TTTTRRRRUUUUEEEE) the bit with index iiii. The index iiii must be between 0 and ssssiiiizzzzeeee----1. No bounds checking is performed. The following are equivalent, although sssseeeettttBBBBiiiitttt((((ssssiiiizzzzeeee____tttt)))) is slightly smaller and faster than using ooooppppeeeerrrraaaattttoooorrrr(((())))((((ssssiiiizzzzeeee____tttt)))): a(i) = TRUE; a.setBit(i); RWBoolean tttteeeessssttttBBBBiiiitttt(size_t i) const; Tests the bit with index iiii. The index iiii must be between 0 and ssssiiiizzzzeeee----1. No bounds checking is performed. The following are equivalent, although tttteeeessssttttBBBBiiiitttt((((ssssiiiizzzzeeee____tttt)))) is slightly smaller and faster than using ooooppppeeeerrrraaaattttoooorrrr(((())))((((ssssiiiizzzzeeee____tttt)))): if( a(i) ) doSomething(); if( a.testBit(i) ) doSomething(); RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll FFFFuuuunnnnccccttttiiiioooonnnnssss RWBitVec ooooppppeeeerrrraaaattttoooorrrr!!!!(const RWBitVec& v); Unary operator that returns the logical negation of vector vvvv. RWBitVec ooooppppeeeerrrraaaattttoooorrrr&&&&(const RWBitVec&,const RWBitVec&); RWBitVec ooooppppeeeerrrraaaattttoooorrrr^^^^(const RWBitVec&,const RWBitVec&); RWBitVec ooooppppeeeerrrraaaattttoooorrrr||||(const RWBitVec&,const RWBitVec&); PPPPaaaaggggeeee 6666 RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++)))) Returns a vector that is the logical AAAANNNNDDDD, XXXXOOOORRRR, or OOOORRRR of the vectors vvvv1111 and vvvv2222. The two vectors must have the same length or an exception of type RRRRWWWWIIIInnnntttteeeerrrrnnnnaaaallllEEEErrrrrrrr will occur. ostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(ostream& s, const RWBitVec& v); Calls vvvv....pppprrrriiiinnnnttttOOOOnnnn((((ssss)))). istream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(istream& s, RWBitVec& v); Calls vvvv....ssssccccaaaannnnFFFFrrrroooommmm((((ssss)))). RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream&, const RWBitVec& vec); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile&, const RWBitVec& vec); Saves the RRRRWWWWBBBBiiiittttVVVVeeeecccc vvvveeeecccc to a virtual stream or RRRRWWWWFFFFiiiilllleeee, respectively. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream&, RWBitVec& vec); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile&, RWBitVec& vec); Restores an RRRRWWWWBBBBiiiittttVVVVeeeecccc into vvvveeeecccc from a virtual stream or RRRRWWWWFFFFiiiilllleeee, respectively, replacing the previous contents of vvvveeeecccc. size_t ssssuuuummmm(const RWBitVec& v); Returns the total number of bits set in the vector vvvv. PPPPaaaaggggeeee 7777